// stl_deque.cpp

#include "auxlib.h"
#include <iostream>
using namespace std;
#include "stl_deque.h"


void allocDequeMatrix(int r,int c,deque< deque<double> > & p)
{
	p.resize(r);
	for (int i=0 ; i < r ; i++)
		p[i].resize(c);
}

void fillDequeMatrix(deque< deque<double> > & p, 
					 int r, int c, double d) 
{
	for (int i=0 ; i < r ; i++) {
		for (int j=0 ; j < c ; j++) {
			p[i][j] = d;
		}
	}
}

void addToDequeMatrix(deque< deque<double> > & p, int r, int c, double d) 
{
	for (int i=0 ; i < r ; i++) {
		for (int j=0 ; j < c ; j++) {
			p[i][j] += d;
		}
	}
}

void multidimensional_STL_deque_array(int size) 
{
	cout << "=== multidimensiona_STL_deque_array, size=" << size << endl;
	double eps = 1e-8;
	MyClock clk;
	double duration_sec;
	clk.markTime();
	// code to test begin (1)
	int row = size, col = size;
	deque< deque<double> > p;
	allocDequeMatrix(row,col,p);
	fillDequeMatrix(p,row,col,1.1);
	duration_sec = clk.getDiffTime();
	cout << "alloc & fill matrix=" << duration_sec << " sec" << endl;
	// code to test begin (2)
	clk.markTime();
	addToDequeMatrix(p,row,col,2.2);
	duration_sec = clk.getDiffTime();
	cout << "addToMatrix=" << duration_sec << " sec" << endl;
	// code to test end (2)

	// confirm that add was done
	myAssert(nearEqual(p[2][3],3.3,eps));
}

